import request from '@/utils/request';

const baseURL = '/energy';

/**
 * 能源大类列表
 */
export const getTypeList = () =>
  request({
    method: 'GET',
    url: `${baseURL}/type/list`
  });

/**
 * 能源大类 更新或创建
 * @param {{
  id?: number;
  name: string;
  energyType: string;
  num: number;
}} [data]
 */
export const saveOrUpdateType = data =>
  request({
    method: 'POST',
    url: `${baseURL}/type`,
    data
  });

/**
 * 能源大类 删除
 * @param {number} id
 * @returns
 */
export const deleteTypeById = id =>
  request({
    method: 'POST',
    url: `${baseURL}/type/${id}`
  });

/**
 * 能源子类列表
 * @param {string} type
 */
export const getTypeKindList = type =>
  request({
    method: 'GET',
    url: `${baseURL}/kind/list/${type}`
  });

/**
 * 能源子类 更新或创建
 * @param {{
  id?: number;
  energyType: string;
  energyName: string;
  code: string;
  energyUnit: string;
  num: number;
  energyUse: string;
}} [data]
 */
export const saveOrUpdateKind = data =>
  request({
    method: 'POST',
    url: `${baseURL}/kind`,
    data
  });

/**
 * 能源子类 删除
 * @param {number} id
 * @returns
 */
export const deleteKindById = id =>
  request({
    method: 'POST',
    url: `${baseURL}/kind/${id}`
  });

/**
 * 获取能源编码字典
 */
export const getEnergyCode = () =>
  request({
    method: 'GET',
    url: `${baseURL}/energyCode/list`
  });

/** --------------- 能效分析 --------------- */
/**
 * 产值单耗分析（产值单耗分析-数据总览卡片）
 * @param {{timeType: string, time: string}} params
 * @returns
 */
export const getEnergyValueSingleCost = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/output/consumption/tip`,
    params
  });

/**  */
/**
 * 产值单耗分析图表 时间纬度（产值指标趋势）
 * @param {{timeType: string, time: string}} params
 * @returns
 */
export const getEnergyValueSingleCostTrend = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/output/consumption/time/chart`,
    params
  });

/**
 * 产值单耗分析排名表 产值类型纬度（排名图表）
 * @param {{timeType: string, time: string}} params
 * @returns
 */
export const getEnergyValueSingleCostRank = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/output/consumption/type/top`,
    params
  });

/**
 * 能效分析-能耗指标异常分析-趋势分析
 * @param {string} areaCode
 * @param {string} indicator
 * @param {{timeType: string, time: string}} [options]
 * @returns
 */
export const getEnergyEfficiencyExceptionTrend = (
  areaCode,
  indicator,
  options
) =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/indicator/exception/trend/${areaCode}/${indicator}`,
    options
  });

/**
 * 能效分析-能耗指标异常分析-详情表
 * @param {string} areaCode
 * @param {string} indicator
 * @param {{timeType: string, time: string}} [options]
 * @returns
 */
export const getEnergyEfficiencyExceptionDetail = (
  areaCode,
  indicator,
  options
) =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/indicator/exception/detail/table/${areaCode}/${indicator}`,
    options
  });

/**
 * 能耗指标预测预警-趋势分析
 * @param {string} areaCode
 * @param {string} indicator
 * @param {{timeType: string, time: string}} [options]
 * @returns
 */
export const getIndicatorWarningTrend = (areaCode, indicator, options) =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/indicator/alarm/trend/${areaCode}/${indicator}`,
    options
  });

/**
 * 能耗指标预测预警-详情表
 * @param {string} areaCode
 * @param {string} indicator
 * @param {{timeType: string, time: string}} [options]
 * @returns
 */
export const getIndicatorWarningDetail = (areaCode, indicator, options) =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/indicator/alarm/detail/table/${areaCode}/${indicator}`,
    params: options
  });

/**
 * 查询多维度综合报表数据
 * @param {{timeType: string, time: string, areaCode: string, keyword: string}} [params]
 * @returns
 */
export const getComprehensiveReport = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/synthesize`,
    params,
  });

/**
 * 获取重点指标综合分析数据
 * @param {{timeType: string, time: string}} params
 * @returns
 */
export const getKeyIndicatorComplexAnalysis = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/indicator/table`,
    params
  });

/**
 * 能源消费结构分析-能源消费情况分析
 * @param {{timeType:string, time:string}} params
 * @returns
 */
export const getEnergyConsumptionStructureAnalysis = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/product/consumption/overview/analysis`,
    params
  });

/**
 * 能源消费结构分析-能源消费总量趋势
 * @param {{timeType:string, time:string}} params
 * @returns
 */
export const getEnergyConsumptionStructureTrend = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/product/consumption/overview/total`,
    params
  });

/**
 * 能源消费结构分析-能源消费结构及占比
 * @param {{timeType:string, time:string}} params
 * @returns
 */
export const getEnergyConsumptionStructure = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/product/consumption/overview/proportion`,
    params
  });

/**
 * 能效分析-区域分析-区域能源消耗总量
 * @param {{timeType:string, time:string}} params
 * @returns
 */
export const getAreaEnergyConsumptionTotal = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/area/statistics`,
    params
  });

/**
 * 能效分析-区域分析-区域能源消耗排行
 * @param {{timeType:string, time:string}} params
 * @returns
 */
export const getAreaEnergyConsumptionRank = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/area/rank/analysis`,
    params
  });

/**
 * 行业指标综合分析
 * @param {{timeType:string, time:string}} params
 * @returns
 */
export const getIndustryIndexComplexAnalysis = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/industry/table`,
    params
  });

/**
 * 行业能耗分析
 * @param {{timeType:string, time:string}} params
 * @returns
 */
export const getIndustryEnergyAnalysis = params =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/industry/bar`,
    params
  });


/**
 * 能效分析-能源消费排名
 * @param {{timeType:string, time:string}} params
 * @returns
 */
export const getAreaEnergyUseRank = params => request({
  method: 'GET',
  url: `${baseURL}/analyze/rank`,
  params,
})

// --------------------------------------------------------
// ---------------------- 企业分析 -------------------------
// --------------------------------------------------------

/**
 * 企业分析-能源消费情况分析
 * @param {string} enterpriseId
 * @returns
 */
export const getEnergyAnalyzeEnterpriseAnalysis = enterpriseId =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/enterprise/analysis/${enterpriseId}`
  })

/**
 * 企业分析-全年综合能耗累计图
 * @param {string} enterpriseId
 * @returns
 */
export const getEnergyAnalyzeEnterpriseStatistics = enterpriseId =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/enterprise/statistics/${enterpriseId}`
  })


/**
 * 企业分析-综合能耗占比
 * @param {string} enterpriseId
 * @returns
 */
export const getEnergyAnalyzeEnterpriseProportion = enterpriseId =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/enterprise/proportion/${enterpriseId}`
  })


/**
 * 企业分析-各类能源日常用量
 * @param {string} energyType
 * @param {string} enterpriseId
 * @param {{time:string,timeType:string}} params
 * @returns
 */
export const getEnergyAnalyzeEnterpriseConsume = (energyType, enterpriseId, params) =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/enterprise/consume/${energyType}/${enterpriseId}`,
    params,
  })

/**
 * 企业分析-上报数据-综合能耗
 * @param {string} enterpriseId
 * @returns
 */
export const getEnergyAnalyzeEnterpriseReport = enterpriseId =>
  request({
    method: 'GET',
    url: `${baseURL}/analyze/enterprise/report/${enterpriseId}`
  })
